package cn.yusei.teamTribe.dao.team;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.yusei.teamTribe.dao.team.po.TeamMemberRequestPO;

@Mapper
public interface TeamMemberRequestDAO {

	final String MEMBER_REQUEST_TABLE = " e_member_request ";
	final String INSERT_FIELDS = " (user_id, team_id, request_reason) ";
	final String SELECT_FIELDS = " id, user_id, team_id, request_reason, result, response_reason, create_time ";
	
	@Insert({"insert into", MEMBER_REQUEST_TABLE, INSERT_FIELDS, "values (#{userId}, #{teamId}, #{requestReason})"})
	void insert(TeamMemberRequestPO tmrPO);
	
	@Update({"update", MEMBER_REQUEST_TABLE, "set result = #{result}, response_reason = #{responseReason} where id = #{id}"})
	void update(TeamMemberRequestPO tmrPO);
	
	@Select({"select", SELECT_FIELDS, "from", MEMBER_REQUEST_TABLE, "where id = #{id}"})
	TeamMemberRequestPO select(@Param("id") int id);
	
	@Select({"select team_id from", MEMBER_REQUEST_TABLE, "where id = #{id}"})
	Integer selectTeamId(@Param("id") int id);
	
	@Select({"select user_id from", MEMBER_REQUEST_TABLE, "where id = #{id}"})
	int selectUserId(@Param("id") int id);
	
	@Select({"select last_insert_id()"})
	int selectLastInsertId();
	
}
